/*
@author: stanfor
@date: 2022/8/22 18:11
@Version: 1.0
@last modify time : 2022/8/22 18:11
*/

import React, { FC, ReactElement, useState } from 'react';
import { Radio, Col, Form, RadioGroupProps } from 'antd';
import { getRulesConfig, commonInterface } from '@C/base/SFields/constant';
import './index.less';

const defaultOptions = [
  { label: 'A', value: 'A', },
  { label: 'B', value: 'B', disabled: true },
  { label: 'C', value: 'C', },
];

const Index: FC<Partial<commonInterface> & Partial<RadioGroupProps>> = (props): ReactElement => {
  const { name, label = 'Radio', span = 8, required = false, ruleIcon, options, formItemConfig, ...radioProps } = props;

  const [value, setValue] = useState('');
  const onChange = ({ target }: any) => {
    setValue(target.value);
  };

  return (
    <Col span={span}>
      <div className="base-component-super-fields-common">
        <Form.Item
          name={name}
          label={label}
          rules={getRulesConfig(required, label, ruleIcon, '请至少勾选其中一项')}
          {...formItemConfig}
        >
          <Radio.Group value={value} onChange={onChange} options={options || defaultOptions} {...radioProps} />
        </Form.Item>
      </div>
    </Col>
  );
};

export default Index;
